#[doc = "Register `SPICR0` reader"]
pub struct R(crate::R<SPICR0_SPEC>);
impl core::ops::Deref for R {
    type Target = crate::R<SPICR0_SPEC>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
impl core::convert::From<crate::R<SPICR0_SPEC>> for R {
    fn from(reader: crate::R<SPICR0_SPEC>) -> Self {
        R(reader)
    }
}
#[doc = "Register `SPICR0` writer"]
pub struct W(crate::W<SPICR0_SPEC>);
impl core::ops::Deref for W {
    type Target = crate::W<SPICR0_SPEC>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
impl core::ops::DerefMut for W {
    #[inline(always)]
    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.0
    }
}
impl core::convert::From<crate::W<SPICR0_SPEC>> for W {
    fn from(writer: crate::W<SPICR0_SPEC>) -> Self {
        W(writer)
    }
}
#[doc = "Field `scr` reader - Serial clock rate, ranging from 0 to 255."]
pub struct SCR_R(crate::FieldReader<u8, u8>);
impl SCR_R {
    pub(crate) fn new(bits: u8) -> Self {
        SCR_R(crate::FieldReader::new(bits))
    }
}
impl core::ops::Deref for SCR_R {
    type Target = crate::FieldReader<u8, u8>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
#[doc = "Field `scr` writer - Serial clock rate, ranging from 0 to 255."]
pub struct SCR_W<'a> {
    w: &'a mut W,
}
impl<'a> SCR_W<'a> {
    #[doc = r"Writes raw bits to the field"]
    #[inline(always)]
    pub unsafe fn bits(self, value: u8) -> &'a mut W {
        self.w.bits = (self.w.bits & !(0xff << 8)) | (((value as u16) & 0xff) << 8);
        self.w
    }
}
#[doc = "Field `sph` reader - SPICLKOUT phase."]
pub struct SPH_R(crate::FieldReader<bool, bool>);
impl SPH_R {
    pub(crate) fn new(bits: bool) -> Self {
        SPH_R(crate::FieldReader::new(bits))
    }
}
impl core::ops::Deref for SPH_R {
    type Target = crate::FieldReader<bool, bool>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
#[doc = "Field `sph` writer - SPICLKOUT phase."]
pub struct SPH_W<'a> {
    w: &'a mut W,
}
impl<'a> SPH_W<'a> {
    #[doc = r"Sets the field bit"]
    #[inline(always)]
    pub fn set_bit(self) -> &'a mut W {
        self.bit(true)
    }
    #[doc = r"Clears the field bit"]
    #[inline(always)]
    pub fn clear_bit(self) -> &'a mut W {
        self.bit(false)
    }
    #[doc = r"Writes raw bits to the field"]
    #[inline(always)]
    pub fn bit(self, value: bool) -> &'a mut W {
        self.w.bits = (self.w.bits & !(0x01 << 7)) | (((value as u16) & 0x01) << 7);
        self.w
    }
}
#[doc = "Field `spo` reader - SPICLKOUT polarity."]
pub struct SPO_R(crate::FieldReader<bool, bool>);
impl SPO_R {
    pub(crate) fn new(bits: bool) -> Self {
        SPO_R(crate::FieldReader::new(bits))
    }
}
impl core::ops::Deref for SPO_R {
    type Target = crate::FieldReader<bool, bool>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
#[doc = "Field `spo` writer - SPICLKOUT polarity."]
pub struct SPO_W<'a> {
    w: &'a mut W,
}
impl<'a> SPO_W<'a> {
    #[doc = r"Sets the field bit"]
    #[inline(always)]
    pub fn set_bit(self) -> &'a mut W {
        self.bit(true)
    }
    #[doc = r"Clears the field bit"]
    #[inline(always)]
    pub fn clear_bit(self) -> &'a mut W {
        self.bit(false)
    }
    #[doc = r"Writes raw bits to the field"]
    #[inline(always)]
    pub fn bit(self, value: bool) -> &'a mut W {
        self.w.bits = (self.w.bits & !(0x01 << 6)) | (((value as u16) & 0x01) << 6);
        self.w
    }
}
#[doc = "Frame format select.\n\nValue on reset: 0"]
#[derive(Clone, Copy, Debug, PartialEq)]
#[repr(u8)]
pub enum FRF_A {
    #[doc = "0: Motorola SPI frame format."]
    MOTOROLA_SPI = 0,
    #[doc = "1: TI synchronous serial frame."]
    TI_SYNCHRONOUS = 1,
    #[doc = "2: National Microwire frame format."]
    NATIONAL_MICROWIRE = 2,
}
impl From<FRF_A> for u8 {
    #[inline(always)]
    fn from(variant: FRF_A) -> Self {
        variant as _
    }
}
#[doc = "Field `frf` reader - Frame format select."]
pub struct FRF_R(crate::FieldReader<u8, FRF_A>);
impl FRF_R {
    pub(crate) fn new(bits: u8) -> Self {
        FRF_R(crate::FieldReader::new(bits))
    }
    #[doc = r"Get enumerated values variant"]
    #[inline(always)]
    pub fn variant(&self) -> crate::Variant<u8, FRF_A> {
        use crate::Variant::*;
        match self.bits {
            0 => Val(FRF_A::MOTOROLA_SPI),
            1 => Val(FRF_A::TI_SYNCHRONOUS),
            2 => Val(FRF_A::NATIONAL_MICROWIRE),
            i => Res(i),
        }
    }
    #[doc = "Checks if the value of the field is `MOTOROLA_SPI`"]
    #[inline(always)]
    pub fn is_motorola_spi(&self) -> bool {
        **self == FRF_A::MOTOROLA_SPI
    }
    #[doc = "Checks if the value of the field is `TI_SYNCHRONOUS`"]
    #[inline(always)]
    pub fn is_ti_synchronous(&self) -> bool {
        **self == FRF_A::TI_SYNCHRONOUS
    }
    #[doc = "Checks if the value of the field is `NATIONAL_MICROWIRE`"]
    #[inline(always)]
    pub fn is_national_microwire(&self) -> bool {
        **self == FRF_A::NATIONAL_MICROWIRE
    }
}
impl core::ops::Deref for FRF_R {
    type Target = crate::FieldReader<u8, FRF_A>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
#[doc = "Field `frf` writer - Frame format select."]
pub struct FRF_W<'a> {
    w: &'a mut W,
}
impl<'a> FRF_W<'a> {
    #[doc = r"Writes `variant` to the field"]
    #[inline(always)]
    pub fn variant(self, variant: FRF_A) -> &'a mut W {
        unsafe { self.bits(variant.into()) }
    }
    #[doc = "Motorola SPI frame format."]
    #[inline(always)]
    pub fn motorola_spi(self) -> &'a mut W {
        self.variant(FRF_A::MOTOROLA_SPI)
    }
    #[doc = "TI synchronous serial frame."]
    #[inline(always)]
    pub fn ti_synchronous(self) -> &'a mut W {
        self.variant(FRF_A::TI_SYNCHRONOUS)
    }
    #[doc = "National Microwire frame format."]
    #[inline(always)]
    pub fn national_microwire(self) -> &'a mut W {
        self.variant(FRF_A::NATIONAL_MICROWIRE)
    }
    #[doc = r"Writes raw bits to the field"]
    #[inline(always)]
    pub unsafe fn bits(self, value: u8) -> &'a mut W {
        self.w.bits = (self.w.bits & !(0x03 << 4)) | (((value as u16) & 0x03) << 4);
        self.w
    }
}
#[doc = "Data bit width.\n\nValue on reset: 0"]
#[derive(Clone, Copy, Debug, PartialEq)]
#[repr(u8)]
pub enum DSS_A {
    #[doc = "3: 4 bits."]
    WIDTH_4 = 3,
    #[doc = "4: 5 bits."]
    WIDTH_5 = 4,
    #[doc = "5: 6 bits."]
    WIDTH_6 = 5,
    #[doc = "6: 7 bits."]
    WIDTH_7 = 6,
    #[doc = "7: 8 bits."]
    WIDTH_8 = 7,
    #[doc = "8: 9 bits."]
    WIDTH_9 = 8,
    #[doc = "9: 10 bits."]
    WIDTH_10 = 9,
    #[doc = "10: 11 bits."]
    WIDTH_11 = 10,
    #[doc = "11: 12 bits."]
    WIDTH_12 = 11,
    #[doc = "12: 13 bits."]
    WIDTH_13 = 12,
    #[doc = "13: 14 bits."]
    WIDTH_14 = 13,
    #[doc = "14: 15 bits."]
    WIDTH_15 = 14,
    #[doc = "15: 16 bits."]
    WIDTH_16 = 15,
}
impl From<DSS_A> for u8 {
    #[inline(always)]
    fn from(variant: DSS_A) -> Self {
        variant as _
    }
}
#[doc = "Field `dss` reader - Data bit width."]
pub struct DSS_R(crate::FieldReader<u8, DSS_A>);
impl DSS_R {
    pub(crate) fn new(bits: u8) -> Self {
        DSS_R(crate::FieldReader::new(bits))
    }
    #[doc = r"Get enumerated values variant"]
    #[inline(always)]
    pub fn variant(&self) -> crate::Variant<u8, DSS_A> {
        use crate::Variant::*;
        match self.bits {
            3 => Val(DSS_A::WIDTH_4),
            4 => Val(DSS_A::WIDTH_5),
            5 => Val(DSS_A::WIDTH_6),
            6 => Val(DSS_A::WIDTH_7),
            7 => Val(DSS_A::WIDTH_8),
            8 => Val(DSS_A::WIDTH_9),
            9 => Val(DSS_A::WIDTH_10),
            10 => Val(DSS_A::WIDTH_11),
            11 => Val(DSS_A::WIDTH_12),
            12 => Val(DSS_A::WIDTH_13),
            13 => Val(DSS_A::WIDTH_14),
            14 => Val(DSS_A::WIDTH_15),
            15 => Val(DSS_A::WIDTH_16),
            i => Res(i),
        }
    }
    #[doc = "Checks if the value of the field is `WIDTH_4`"]
    #[inline(always)]
    pub fn is_width_4(&self) -> bool {
        **self == DSS_A::WIDTH_4
    }
    #[doc = "Checks if the value of the field is `WIDTH_5`"]
    #[inline(always)]
    pub fn is_width_5(&self) -> bool {
        **self == DSS_A::WIDTH_5
    }
    #[doc = "Checks if the value of the field is `WIDTH_6`"]
    #[inline(always)]
    pub fn is_width_6(&self) -> bool {
        **self == DSS_A::WIDTH_6
    }
    #[doc = "Checks if the value of the field is `WIDTH_7`"]
    #[inline(always)]
    pub fn is_width_7(&self) -> bool {
        **self == DSS_A::WIDTH_7
    }
    #[doc = "Checks if the value of the field is `WIDTH_8`"]
    #[inline(always)]
    pub fn is_width_8(&self) -> bool {
        **self == DSS_A::WIDTH_8
    }
    #[doc = "Checks if the value of the field is `WIDTH_9`"]
    #[inline(always)]
    pub fn is_width_9(&self) -> bool {
        **self == DSS_A::WIDTH_9
    }
    #[doc = "Checks if the value of the field is `WIDTH_10`"]
    #[inline(always)]
    pub fn is_width_10(&self) -> bool {
        **self == DSS_A::WIDTH_10
    }
    #[doc = "Checks if the value of the field is `WIDTH_11`"]
    #[inline(always)]
    pub fn is_width_11(&self) -> bool {
        **self == DSS_A::WIDTH_11
    }
    #[doc = "Checks if the value of the field is `WIDTH_12`"]
    #[inline(always)]
    pub fn is_width_12(&self) -> bool {
        **self == DSS_A::WIDTH_12
    }
    #[doc = "Checks if the value of the field is `WIDTH_13`"]
    #[inline(always)]
    pub fn is_width_13(&self) -> bool {
        **self == DSS_A::WIDTH_13
    }
    #[doc = "Checks if the value of the field is `WIDTH_14`"]
    #[inline(always)]
    pub fn is_width_14(&self) -> bool {
        **self == DSS_A::WIDTH_14
    }
    #[doc = "Checks if the value of the field is `WIDTH_15`"]
    #[inline(always)]
    pub fn is_width_15(&self) -> bool {
        **self == DSS_A::WIDTH_15
    }
    #[doc = "Checks if the value of the field is `WIDTH_16`"]
    #[inline(always)]
    pub fn is_width_16(&self) -> bool {
        **self == DSS_A::WIDTH_16
    }
}
impl core::ops::Deref for DSS_R {
    type Target = crate::FieldReader<u8, DSS_A>;
    #[inline(always)]
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
#[doc = "Field `dss` writer - Data bit width."]
pub struct DSS_W<'a> {
    w: &'a mut W,
}
impl<'a> DSS_W<'a> {
    #[doc = r"Writes `variant` to the field"]
    #[inline(always)]
    pub fn variant(self, variant: DSS_A) -> &'a mut W {
        unsafe { self.bits(variant.into()) }
    }
    #[doc = "4 bits."]
    #[inline(always)]
    pub fn width_4(self) -> &'a mut W {
        self.variant(DSS_A::WIDTH_4)
    }
    #[doc = "5 bits."]
    #[inline(always)]
    pub fn width_5(self) -> &'a mut W {
        self.variant(DSS_A::WIDTH_5)
    }
    #[doc = "6 bits."]
    #[inline(always)]
    pub fn width_6(self) -> &'a mut W {
        self.variant(DSS_A::WIDTH_6)
    }
    #[doc = "7 bits."]
    #[inline(always)]
    pub fn width_7(self) -> &'a mut W {
        self.variant(DSS_A::WIDTH_7)
    }
    #[doc = "8 bits."]
    #[inline(always)]
    pub fn width_8(self) -> &'a mut W {
        self.variant(DSS_A::WIDTH_8)
    }
    #[doc = "9 bits."]
    #[inline(always)]
    pub fn width_9(self) -> &'a mut W {
        self.variant(DSS_A::WIDTH_9)
    }
    #[doc = "10 bits."]
    #[inline(always)]
    pub fn width_10(self) -> &'a mut W {
        self.variant(DSS_A::WIDTH_10)
    }
    #[doc = "11 bits."]
    #[inline(always)]
    pub fn width_11(self) -> &'a mut W {
        self.variant(DSS_A::WIDTH_11)
    }
    #[doc = "12 bits."]
    #[inline(always)]
    pub fn width_12(self) -> &'a mut W {
        self.variant(DSS_A::WIDTH_12)
    }
    #[doc = "13 bits."]
    #[inline(always)]
    pub fn width_13(self) -> &'a mut W {
        self.variant(DSS_A::WIDTH_13)
    }
    #[doc = "14 bits."]
    #[inline(always)]
    pub fn width_14(self) -> &'a mut W {
        self.variant(DSS_A::WIDTH_14)
    }
    #[doc = "15 bits."]
    #[inline(always)]
    pub fn width_15(self) -> &'a mut W {
        self.variant(DSS_A::WIDTH_15)
    }
    #[doc = "16 bits."]
    #[inline(always)]
    pub fn width_16(self) -> &'a mut W {
        self.variant(DSS_A::WIDTH_16)
    }
    #[doc = r"Writes raw bits to the field"]
    #[inline(always)]
    pub unsafe fn bits(self, value: u8) -> &'a mut W {
        self.w.bits = (self.w.bits & !0x0f) | ((value as u16) & 0x0f);
        self.w
    }
}
impl R {
    #[doc = "Bits 8:15 - Serial clock rate, ranging from 0 to 255."]
    #[inline(always)]
    pub fn scr(&self) -> SCR_R {
        SCR_R::new(((self.bits >> 8) & 0xff) as u8)
    }
    #[doc = "Bit 7 - SPICLKOUT phase."]
    #[inline(always)]
    pub fn sph(&self) -> SPH_R {
        SPH_R::new(((self.bits >> 7) & 0x01) != 0)
    }
    #[doc = "Bit 6 - SPICLKOUT polarity."]
    #[inline(always)]
    pub fn spo(&self) -> SPO_R {
        SPO_R::new(((self.bits >> 6) & 0x01) != 0)
    }
    #[doc = "Bits 4:5 - Frame format select."]
    #[inline(always)]
    pub fn frf(&self) -> FRF_R {
        FRF_R::new(((self.bits >> 4) & 0x03) as u8)
    }
    #[doc = "Bits 0:3 - Data bit width."]
    #[inline(always)]
    pub fn dss(&self) -> DSS_R {
        DSS_R::new((self.bits & 0x0f) as u8)
    }
}
impl W {
    #[doc = "Bits 8:15 - Serial clock rate, ranging from 0 to 255."]
    #[inline(always)]
    pub fn scr(&mut self) -> SCR_W {
        SCR_W { w: self }
    }
    #[doc = "Bit 7 - SPICLKOUT phase."]
    #[inline(always)]
    pub fn sph(&mut self) -> SPH_W {
        SPH_W { w: self }
    }
    #[doc = "Bit 6 - SPICLKOUT polarity."]
    #[inline(always)]
    pub fn spo(&mut self) -> SPO_W {
        SPO_W { w: self }
    }
    #[doc = "Bits 4:5 - Frame format select."]
    #[inline(always)]
    pub fn frf(&mut self) -> FRF_W {
        FRF_W { w: self }
    }
    #[doc = "Bits 0:3 - Data bit width."]
    #[inline(always)]
    pub fn dss(&mut self) -> DSS_W {
        DSS_W { w: self }
    }
    #[doc = "Writes raw bits to the register."]
    pub unsafe fn bits(&mut self, bits: u16) -> &mut Self {
        self.0.bits(bits);
        self
    }
}
#[doc = "SPICR0 is SPI control register 0.\n\nThis register you can [`read`](crate::generic::Reg::read), [`write_with_zero`](crate::generic::Reg::write_with_zero), [`reset`](crate::generic::Reg::reset), [`write`](crate::generic::Reg::write), [`modify`](crate::generic::Reg::modify). See [API](https://docs.rs/svd2rust/#read--modify--write-api).\n\nFor information about available fields see [spicr0](index.html) module"]
pub struct SPICR0_SPEC;
impl crate::RegisterSpec for SPICR0_SPEC {
    type Ux = u16;
}
#[doc = "`read()` method returns [spicr0::R](R) reader structure"]
impl crate::Readable for SPICR0_SPEC {
    type Reader = R;
}
#[doc = "`write(|w| ..)` method takes [spicr0::W](W) writer structure"]
impl crate::Writable for SPICR0_SPEC {
    type Writer = W;
}
#[doc = "`reset()` method sets SPICR0 to value 0"]
impl crate::Resettable for SPICR0_SPEC {
    #[inline(always)]
    fn reset_value() -> Self::Ux {
        0
    }
}
